home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 7.4 KB | 257 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWArcShp.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWARCSHP_H
- #include "FWArcShp.h"
- #endif
-
- #ifndef FWOVLSHP_H
- #include "FWOvlShp.h"
- #endif
-
- #ifndef SLRENDER_H
- #include "SLRender.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- C Includes -----
-
- #if defined(FW_BUILD_MAC) & !defined(__FP__)
- #include <FP.h>
- #endif
-
- #ifdef FW_BUILD_WIN
- #include <math.h>
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgraphxshape
- #endif
-
- //========================================================================================
- // class FW_CArcShape
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CArcShape)
- FW_DEFINE_CLASS_M1(FW_CArcShape, FW_CBoundedShape)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::FW_CArcShape
- //----------------------------------------------------------------------------------------
-
- FW_CArcShape::FW_CArcShape(const FW_CArcShape& other) :
- FW_CBoundedShape(other),
- fStartAngle(other.fStartAngle),
- fArcAngle(other.fArcAngle)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::FW_CArcShape
- //----------------------------------------------------------------------------------------
-
- FW_CArcShape::FW_CArcShape(const FW_CRect& rect,
- short startAngle,
- short arcAngle,
- FW_ERenderVerbs renderVerb,
- const FW_CInk& ink,
- const FW_CStyle& style) :
- FW_CBoundedShape(rect, renderVerb, ink, style, FW_kNormalFont),
- fStartAngle(startAngle),
- fArcAngle(arcAngle)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::FW_CArcShape
- //----------------------------------------------------------------------------------------
-
- FW_CArcShape::FW_CArcShape(FW_CReadableStream& stream) :
- FW_CBoundedShape(stream)
- {
- stream >> fStartAngle;
- stream >> fArcAngle;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::~FW_CArcShape
- //----------------------------------------------------------------------------------------
-
- FW_CArcShape::~FW_CArcShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CArcShape& FW_CArcShape::operator=(const FW_CArcShape& other)
- {
- if (this != &other)
- {
- FW_CBoundedShape::operator=(other);
-
- fStartAngle = other.fStartAngle;
- fArcAngle = other.fArcAngle;
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CArcShape::Render(FW_CGraphicContext& gc) const
- {
- FW_PrivRenderArc(gc.GetEnvironment(),
- gc,
- fRect,
- fStartAngle, fArcAngle,
- GetRenderVerb(),
- fInk,
- fStyle);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::RenderArc
- //----------------------------------------------------------------------------------------
-
- void FW_CArcShape::RenderArc(FW_CGraphicContext& gc,
- const FW_CRect& rect,
- short startAngle, short arcAngle,
- FW_ERenderVerbs renderVerb,
- const FW_CInk& ink,
- const FW_CStyle& style)
- {
- FW_PrivRenderArc(gc.GetEnvironment(),
- gc,
- rect,
- startAngle, arcAngle,
- renderVerb,
- ink,
- style);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::CalcAngle
- //----------------------------------------------------------------------------------------
-
- short FW_CArcShape::CalcAngle(const FW_CPoint& test) const
- {
- FW_Double width = FW_FixedToDouble(fRect.right - fRect.left);
- FW_Double height = FW_FixedToDouble(fRect.bottom - fRect.top);
-
- FW_CPoint testPoint(FW_Half(test.x + test.x - fRect.right - fRect.left), FW_Half(test.y + test.y - fRect.bottom - fRect.top));
-
- if (testPoint.y == FW_kFixed0 || height == 0)
- return testPoint.x < FW_kFixed0 ? 270 : 90;
-
- if (testPoint.x == FW_kFixed0 || width == 0)
- return testPoint.y < FW_kFixed0 ? 180 : 0;
-
- FW_Double arc = atan((FW_FixedToDouble(testPoint.y) * height) / (FW_FixedToDouble(testPoint.x) * width));
-
- arc = ((180.0 * arc) / 3.1415926536) + .5;
- short shortArc = (short)arc + 90;
- if (testPoint.x < FW_kFixed0)
- shortArc += 180;
-
- return shortArc;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CArcShape::HitTest(FW_CGraphicContext& gc,
- const FW_CPoint& test,
- FW_Fixed tolerance) const
- {
- if(fRenderVerb == FW_kNoRendering)
- return FALSE;
-
- if (FW_CBoundedShape::HitTest(gc, test, tolerance))
- {
- short arcAngle = CalcAngle(test) - fStartAngle;
- if (((arcAngle & 0x8000) == (fArcAngle & 0x8000)) && // same sign
- FW_Absolute((long)fArcAngle) >= FW_Absolute((long)arcAngle))
- {
- FW_COvalShape oval(fRect, fRenderVerb);
- return oval.HitTest(gc, test, tolerance);
- }
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CArcShape::Copy() const
- {
- return FW_NEW(FW_CArcShape, (*this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::GetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CArcShape::GetGeometry(FW_CRect& rect, short& startAngle, short& arcAngle) const
- {
- rect = fRect;
- startAngle = fStartAngle;
- arcAngle = fArcAngle;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::SetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CArcShape::SetGeometry(const FW_CRect& rect, short startAngle, short arcAngle)
- {
- fRect = rect;
- fStartAngle = startAngle;
- fArcAngle = arcAngle;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CArcShape::Flatten(FW_CWritableStream& stream) const
- {
- FW_CBoundedShape::Flatten(stream);
- stream << fStartAngle;
- stream << fArcAngle;
- }
-